package jbrowser.pacman.demo.util;

/**
 * *****************************************************************************
 * Copyright (c) 2010-2011 Sonatype, Inc. All rights reserved. This program and
 * the accompanying materials are made available under the terms of the Eclipse
 * Public License v1.0 which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * *****************************************************************************
 */
import org.apache.maven.repository.internal.MavenRepositorySystemSession;
import org.sonatype.aether.RepositorySystem;
import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.repository.LocalRepository;
import org.sonatype.aether.repository.RemoteRepository;

import jbrowser.pacman.demo.manual.ManualRepositorySystemFactory;

/**
 * A helper to boot the repository system and a repository system session.
 */
public class Pacman {

    public static String getLocalRepository() {
        return System.getProperty("user.home") + System.getProperty("file.separator") + ".m2" + System.getProperty("file.separator") + "repository";
        //return System.getProperty("user.home") + System.getProperty("file.separator") + ".m2" + System.getProperty("file.separator") + "repository";
    }

    public static RepositorySystem newRepositorySystem() {
        return ManualRepositorySystemFactory.newRepositorySystem();
    }

    public static RepositorySystemSession newRepositorySystemSession(RepositorySystem system) {
        MavenRepositorySystemSession session = new MavenRepositorySystemSession();

        //  LocalRepository localRepo = new LocalRepository("target/local-repo");
        LocalRepository localRepo = new LocalRepository(getLocalRepository());
        session.setLocalRepositoryManager(system.newLocalRepositoryManager(localRepo));

        session.setTransferListener(new ConsoleTransferListener());
        session.setRepositoryListener(new ConsoleRepositoryListener());

        // uncomment to generate dirty trees
        // session.setDependencyGraphTransformer( null );

        return session;
    }

    public static RemoteRepository newCentralRepository() {
        return new RemoteRepository("central", "default", "http://repo1.maven.org/maven2/");
    }
}
